//
//  HHYStockListTCell.m
//  宝宝病例
//
//  Created by apple on 2019/6/10.
//  Copyright © 2019 apple. All rights reserved.
//

#import "HHYStockListTCell.h"

#import "HHYHeader.h"

@interface HHYStockListTCell ()

@property (weak, nonatomic) IBOutlet UIButton *addBtn;

@property (weak, nonatomic) IBOutlet UILabel *nameLabel;

@property (weak, nonatomic) IBOutlet UILabel *codeLabel;
@property (weak, nonatomic) IBOutlet UILabel *firstContentLabel;
@property (weak, nonatomic) IBOutlet UILabel *secondContentLabel;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *lefiConstrint;
@end

@implementation HHYStockListTCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)setStockModel:(HHYStockDisplayModel *)stockModel {
    _stockModel = stockModel;
    
    self.nameLabel.text = stockModel.name;
    self.codeLabel.text = stockModel.symbol;
    
    switch (_displayType) {
        case HHYStockListTCellDisplayType1://买入、卖出
        {
            self.firstContentLabel.text = stockModel.buy;
            self.secondContentLabel.text = stockModel.sell;
        }
            break;
        case HHYStockListTCellDisplayType2://涨跌幅
        {
            self.firstContentLabel.text = stockModel.trade;
            self.secondContentLabel.text = stockModel.changepercent;
        }
            break;
        case HHYStockListTCellDisplayType3://成交
        {
            self.firstContentLabel.text = stockModel.volume;
            self.secondContentLabel.text = stockModel.amount;
        }
            break;
        default:
            break;
    }
    //设置字体颜色
    //默认
    self.firstContentLabel.textColor = UIColor.blackColor;
    self.secondContentLabel.textColor = self.firstContentLabel.textColor;
    
    CGFloat changepercent_num = [stockModel.changepercent floatValue];
    if (changepercent_num > 0) {
        //涨  红色
        self.firstContentLabel.textColor = rgba(255, 0, 0, 1);
        self.secondContentLabel.textColor = self.firstContentLabel.textColor;
    } else if(changepercent_num < 0){
        //跌 绿色
        self.firstContentLabel.textColor = rgba(0, 203, 59, 1);
        self.secondContentLabel.textColor = self.firstContentLabel.textColor;
    }
    
    if (_displayType == HHYStockListTCellDisplayType3){
        self.firstContentLabel.textColor = UIColor.blackColor;
        self.secondContentLabel.textColor = self.firstContentLabel.textColor;
    }
}

- (IBAction)addAction:(UIButton *)sender {
    HHYZXStockLocalModel *lModel = [HHYZXStockLocalModel new];
    
    lModel.symbol = self.stockModel.symbol;
    lModel.name = self.stockModel.name;
    lModel.trade = self.stockModel.trade;
    lModel.changepercent = self.stockModel.changepercent;
    lModel.buy = self.stockModel.buy;
    lModel.sell = self.stockModel.sell;
    lModel.userID = [DGPUtil getCurrentUserID];
    lModel.createTime = [NSDate.date timeIntervalSince1970];
    [DGPUtil addZiXuanModel:lModel successCallback:^{
        [HHYUtils textExampleLong:@"已添加到“自选”"];
    } failedCallback:^{
        [HHYUtils textExampleLong:@"已添加到“自选”"];
    }];
    
}


- (void)setHideAddBtn:(BOOL)hideAddBtn {
    _hideAddBtn = hideAddBtn;
    self.addBtn.hidden = hideAddBtn;
    self.lefiConstrint.constant = hideAddBtn?10:40;
}

@end
